package com.cykj.controller;

import com.cykj.service.ImageCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.OutputStream;
@CrossOrigin
@RestController
public class CodeController {
    @Autowired
    private ImageCodeUtils codeService;

    @RequestMapping("/code")
    public void getCode(OutputStream os) {

        codeService.createImage();
        System.out.println(codeService.getCode());
        try {
            codeService.write(os);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
